//
//  LKWelcomeViewController.swift
//  LKWeibo
//
//  Created by like on 16/8/12.
//  Copyright © 2016年 like. All rights reserved.
//

import UIKit
import SDWebImage

class LKWelcomeViewController: UIViewController {

    override func viewDidAppear(animated: Bool) {
        super.viewDidAppear(animated)
        // 更改头像的顶部约束
        self.headImageView.snp_updateConstraints { (make) -> Void in
            make.top.equalTo(self.view).offset(100)
        }
        
        // 设置动画
        /*
         时间  延迟时间   阻尼系数 (越小 弹性效果越大)  起始速度   options
         */
        UIView.animateWithDuration(2, delay: 1, usingSpringWithDamping: 0.7, initialSpringVelocity: 0, options: [], animations: { () -> Void in
            //强制刷新UI
            self.view.layoutIfNeeded()
        }) { (_) -> Void in
            UIView.animateWithDuration(0.25, animations: { () -> Void in
                self.messageLabel.alpha = 1
                }, completion: { (_) -> Void in
                    // 发送通知告知appdelegate 切换根控制器
                    NSNotificationCenter.defaultCenter().postNotificationName(WBSWITCHROOTVCNOTIFICATION, object: nil)
            })
        }
        
    }
    
    
    
    
    override func viewDidLoad() {
        super.viewDidLoad()
        setupUI()

    }
    
    
    // MARK: - 设置视图
    private func setupUI(){

        view.addSubview(bgImageView)
        view.addSubview(headImageView)
        view.addSubview(messageLabel)
    
        bgImageView.snp_makeConstraints { (make) -> Void in
            make.edges.equalTo(view).offset(UIEdgeInsetsZero)
        }
        
        headImageView.snp_makeConstraints { (make) -> Void in
            make.size.equalTo(CGSize(width: 90, height: 90))
            make.centerX.equalTo(view)
            make.top.equalTo(view).offset(400)
        }
        
        messageLabel.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(view)
            make.top.equalTo(headImageView.snp_bottom).offset(16)
        }
        
    }

    
    // MARK: - 懒加载控件
    // 背景图片
    private lazy var bgImageView: UIImageView = UIImageView(imgName: "ad_background")
    // 头像
    private lazy var headImageView: UIImageView = {
        let img = UIImageView(imgName: "avatar_default_big")

        img.lk_setImageWithString(LKUserAccountViewModel.sharedTools.userAccount?.avatar_large, placeholderImgName: "avatar_default_big")
        img.layer.cornerRadius = 45
        img.layer.masksToBounds = true
        return img
    }()
    // 欢迎回来
    private lazy var messageLabel: UILabel = {
        let lab = UILabel()
        lab.textColor = UIColor.darkGrayColor()
        lab.textAlignment = .Center
        lab.alpha = 0
        lab.font = UIFont.systemFontOfSize(18)
        lab.text = "欢迎回来"
       
        return lab
    }()


}
